package com.lagou.controller;

import com.lagou.service.IResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private IResumeService resumeService;
    @RequestMapping("/")
    public String root(){
        ModelMap mo = new ModelMap();
        mo.addAttribute("message","用户名:zhangsan,密码:zhangsan");
        return "login";
    }

    @RequestMapping("/login")
    public String login(String loginname, String password, HttpSession session){
//        ModelAndView mav = new ModelAndView();
        ModelMap model = new ModelMap();
        if("zhangsan".equals(loginname)&&"zhangsan".equals(password)){
            session.setAttribute("username","zhangsan");
            model.addAttribute("list",resumeService.findAll());
            return "redirect:find";
        }else{
            model.addAttribute("message","用户名或密码错误");
            return "login";
        }
    }

    //登出
    @RequestMapping("/loginout")
    public ModelAndView loginout(HttpSession session){
        session.removeAttribute("username");
        ModelAndView mv = new ModelAndView();
        mv.setViewName("login");
        return mv;

    }


}
